Inheritance
Warmup
Create a new project called AnimalSpecies
Create an Animal class
tracking age,weight (double), name, species.
- Have a constructor which will
setup all those global variables.
- Have a toString,
- eat method
(taking in double food //which will be how much food in pounds),
- talk (that returns "Hi, I'm Paul ").
- Have getters (getAge, getWeight).
- Have a static variable - totalFood which will track the total
amount of food given to all animals
- Have a static getter for that variable.
Create another class called Shelter that in the main it will
- initialize 2 different animals
- Have each one eat
- Have them talk
- Call toString and print out results
- Print out total food given to all animals
Together
- Create a classes Dog that extend Animal. Keep track of
Breed.
- Create constructor
- Create a getter for breed
- Update talk with relevant info.
- Update toString so it also returns the breed
- Together - lets add to Animal - eat
- Create a new subclass of Dog called PoundDog that will
extend Dog.
- Constructor will initialize a dog but only have weight
and visableAge (as a String (they will put in - puppie,
young, middle age, old). . The name will automatically
be set to "Unknown", the age is -1, and breed will be mutt
- Override the talk command so that it calls the talk of the dog
class then, "please take me home, I dont want to be put down
:<"
- Override the toString method so it also says the visible
age (ie, " and the dog looks young")
- Create a new method beg that will print "give me more"
- Override the eat so it will do the dogs eat then beg, then have it do dogs eat with 1/2 as much food.
- Create some instances:
- an instance of Dog and call each method on your dog
- an instance of PoundDog and call each method on your
pound dog
- find out how much food in total has been fed to all
animals
|